package com.yida.common.core.utils.poi;

import com.yida.common.core.utils.StringUtils;

/**
 * *号替换
 * @author hmh
 *
 */
public class ExcelReplaceHandler implements ExcelHandlerAdapter{

	@Override
	public Object format(Object value, String[] args) {
		String valueInfo = value.toString();
		String type = args[0];
		if("0".equals(type)) {
			return replaceName(valueInfo);
		}
		if("1".equals(type)) {
			return replaceCardNo(valueInfo);
		}
		return "";
	}
	
	/**
	 * 置换姓名为*
	 * @param value 待置换值
	 * @return 结果
	 */
	private String replaceName(String value) {
		int index = 1;
		int length = value.length();
		if(length>3) {
			index = 2;
		}
		return StringUtils.replaceValue(value,"*",index,value.length()-index);
	}
	
	/**
	 * 置换身份证号为*
	 * @param value 待置换值
	 * @return 结果
	 */
	private String replaceCardNo(String value) {
		return StringUtils.replaceValue(value,"*",3,value.length()-3);
	}

}
